package com.hh.serviceImpl;

import com.hh.dao.UsersDao;
import com.hh.entity.Users;
import com.hh.service.UsersService;
import com.hh.util.RedisUtil;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@DubboService(interfaceClass = UsersService.class,version="1.0")
public class UsersServiceImpl implements UsersService {
    @Autowired
    UsersDao usersDao;
    @Autowired
    RedisUtil redisUtils;
    @Override
    public Users getUsers(String userId) {
        Users u=redisUtils.byIdQueryUsersInfo(userId);
        if(u==null){
            Users users=usersDao.queryUsers(userId);//如果redis中没有通过数据库查询
            redisUtils.putUsersInfo(userId,users);//并且将数据放到redis中
            return users;
        }
        return u;
    }
}
